package ecut;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemoStatement {
    public static void main(String[] args) throws Exception{

        //注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接
        String url="jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai";
        Connection connection = DriverManager.getConnection(url,"root","123456");

        //创建Statement对象
        String sql = "select * from user where username = '赵云'";
        Statement statement = connection.createStatement();

        //执行sql语句
        ResultSet resultSet = statement.executeQuery(sql);

        while (resultSet.next()){
            System.out.println(resultSet.getString("username")+"===>"+resultSet.getString("password"));
        }

        resultSet.close();
        statement.close();
        connection.close();
    }
}
